package com.shi.algorithm.recursion.single;

//升序数组
public class E03BinarySearch {

    public static int binarySearch(int[] a, int target){
        return recursion(a, target, 0, a.length - 1);
    }

    public static int recursion(int[] a, int target, int i, int j){
        if (i > j){
            return -1;
        }
        int m = (i + j) >>> 1;
        if (target < a[m]){
            return recursion(a, target, i, m - 1);
        } else if (a[m] < target) {
            return recursion(a, target, m + 1, j);
        } else {
            return m;
        }
    }
}